﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimini/css/public.css" media="all">
    <style>
        .btn-box {
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="btn-box">
        <div id="bindBox"></div>
        <div style="margin-top:30px">
            <button class="layui-btn layui-btn-normal" id="bind-btn">提交绑定</button>
        </div>
    </div>


    <script src="/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['layer', 'transfer'], function () {
            var $ = layui.jquery,
                transfer = layui.transfer;

            var id = window.location.search.substr(4);

            $.ajax({
                url: "/Admin/RoleInfo/GetMenuInfoOptions",
                type: "Get",
                data: {
                    id: id,
                },
                success: function (res) {
                    if (res.code == 200) {
                        // 渲染
                        transfer.render({
                            elem: '#bindBox',
                            data: res.data.options,
                            parseData: function (resule) {
                                return {
                                    "value": resule.id,
                                    "title": resule.title
                                }
                            },
                            value: res.data.menuId,
                            title: ["未绑定菜单", "已绑定菜单"],
                            showSearch: true,
                            id: "bindMenu"
                        });
                    } else {
                        layer.msg(res.msg);
                    }
                }
            })

            $("#bind-btn").click(function (res) {
                var getData = transfer.getData('bindMenu');
                var ids = [];
                for (var i = 0; i < getData.length; i++) {
                    ids.push(getData[i].value)
                }

                $.ajax({
                    url: "/Admin/RoleInfo/BindMenuInfo",
                    type: "Post",
                    data: {
                        menuIds: ids,
                        roleid: id,
                    },
                    success: function (res) {
                        if (res.code == 200) {
                            layer.msg(res.msg);
                        } else {
                            layer.msg(res.msg);
                        }
                    }
                })
            });
        });
    </script>
</body>
</html>
